package com.pomr.service.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pomr.util.common.SimplePropertyFilter;


@Aspect
@Order(2)//设置优先级 日志第二优先级
@Component
public class ControllerLogService {
	private static Logger log = LoggerFactory.getLogger(ControllerLogService.class);
	//声明切入点表达式
	//后面的通知直接使用方法名来引用当前的切点表达式；如果是其他类使用，加上包名即可
	@Pointcut("execution(* com.pomr.controller.*.*.*(..))")
	public void  logAop() {
		// TODO Auto-generated constructor stub
	}
	
	/**
     * 返回
     * 通知
     * @param joinPoint
     */
	@AfterReturning(value="logAop()",returning="result") //controller返回后执行
    public void afterReturnMethod(JoinPoint joinPoint,Object result) throws Exception{
		String methodName = joinPoint.getSignature().getName();
		SimplePropertyFilter cfilter = new SimplePropertyFilter();
        SerializeWriter sw = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(sw);
        serializer.getPropertyFilters().add(cfilter);
        serializer.write(result);
		log.info("类名："+joinPoint.getThis().getClass().getSimpleName()+"方法名："+methodName+" 返回值："+sw.toString(),"张伟");
//		log.info("类名："+joinPoint.getThis().getClass().getSimpleName()+"方法名："+methodName+" 返回值：","张伟");
    }
}
